package tree;

public class SymmetricTree101 {
    public boolean isSymmetric(TreeNode root) {
        return isSymmetric(root.left, root.right);
    }

    public boolean isSymmetric(TreeNode leftRoot, TreeNode rightRoot) {
        if (leftRoot == null && rightRoot == null) {
            return true;
        } else if (leftRoot != null && rightRoot == null) {
            return false;
        } else if (leftRoot == null && rightRoot != null) {
            return false;
        } else {
            if (leftRoot.val != rightRoot.val) {
                return false;
            }
            if (!isSymmetric(leftRoot.left, rightRoot.right)) {
                return false;
            }
            if (!isSymmetric(leftRoot.right, rightRoot.left)) {
                return false;
            }
            return true;
        }
    }
}
